package dimension.starry.gui.Component;

import com.mojang.blaze3d.systems.RenderSystem;
import dimension.starry.StarryDimension;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.client.render.model.json.ModelTransformationMode;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.Item;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

import java.util.function.Supplier;

@Environment(EnvType.CLIENT)
public class ItemButton extends ButtonWidget {

    private static final Identifier BACKGROUND = new Identifier(
        StarryDimension.MOD_ID, "textures/gui/container/slot.png");
    private final Item item;
    private final int left;
    private final int top;

    public ItemButton(int left, int top, Text iTextComponent, Item item, ButtonWidget.PressAction action) {
        super(left, top, 18, 18, iTextComponent, action, Supplier::get);
        this.left = left;
        this.top = top;
        this.item = item;
    }

    @Override
    public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) {
        drawContext.drawTexture(BACKGROUND, this.getX(), this.getY(), 0, 0, width, height, width, height);
        drawContext.drawItem(item.getDefaultStack(), this.left + 1, this.top + 1);
    }

}
